package ${packageName};

<#list importList as item>
import ${item};
</#list>

<#assign serviceVarName = serviceName?substring(0,1)?lower_case+serviceName?substring(1)>
<#assign entityVarName = entityClassName?substring(0,1)?lower_case+entityClassName?substring(1)>
@Api(tags = {"${apiName}Api接口"})
@RestController
@RequestMapping("/${modelName?uncap_first}")
public class ${controllerName}{

    @Autowired
    ${serviceName} ${serviceVarName};

    @XyApiJsonResponses({
            @XyApiJsonResponse(name = "retEntity", value = "返回结果", response = ${entityClassName}.class, array = true)
    })
    @ApiOperation(value = "获取所有的记录",notes = "没有分页功能")
    @PostMapping("/selectAll")
    public ResponseEntity<?> selectAll(){
        return XyResponseEntity.ok(${serviceVarName}.selectAll());
    }

    @XyApiJsonResponses({
        @XyApiJsonResponse(name = "retEntity", value = "返回结果", response = ${entityClassName}.class, array = true)
    })
    @ApiOperation(value = "筛选符合条件的记录")
    @PostMapping("/getSelective")
    public ResponseEntity<?> getSelective(@RequestBody ${entityClassName} ${entityVarName}){
        return XyResponseEntity.ok(${serviceVarName}.getSelective(${entityVarName}));
    }

    @XyApiJsonResponses({
        @XyApiJsonResponse(name = "retEntity", value = "返回结果", response = ${entityClassName}.class, array = true)
    })
    @ApiOperation(value = "获取所有符合条件的记录",notes = "有分页功能")
    @PostMapping("/selectWithPage")
    public ResponseEntity<?> selectWithPage(@RequestBody Map map){
        return XyResponseEntity.ok(${serviceVarName}.selectWithPage(map));
    }

    @XyApiJsonResponses({
        @XyApiJsonResponse(name = "retEntity", value = "返回结果", response = ${entityClassName}.class)
    })
    @ApiOperation(value = "根据主键来获取记录")
    @PostMapping("/getByPrimaryKey")
    public ResponseEntity<?> getByPrimaryKey(@RequestParam ${primaryKey.type} ${primaryKey.varName}){
        return XyResponseEntity.ok(${serviceVarName}.getByPrimaryKey(${primaryKey.varName}));
    }

    @ApiOperation(value = "更新记录")
    @PostMapping("/update")
    public ResponseEntity<?> update(@RequestBody ${entityClassName} ${entityVarName}){
        int rs = ${serviceVarName}.update(${entityVarName});
        if(rs != 0){
            return XyResponseEntity.ok();
        }
        return XyResponseEntity.ok(XyRetCodeConstant.COMMON_OPERATION_FAILTURE);
    }

    @ApiOperation(value = "插入记录")
    @PostMapping("/insert")
    public ResponseEntity<?> insert(@RequestBody @Valid ${entityClassName} ${entityVarName}){
        int rs = ${serviceVarName}.insert(${entityVarName});
        if(rs != 0){
            return XyResponseEntity.ok();
        }
        return XyResponseEntity.ok(XyRetCodeConstant.COMMON_OPERATION_FAILTURE);
    }

    @ApiOperation(value = "插入记录",notes = "存在即更新")
    @PostMapping("/saveOrUpdate")
    public ResponseEntity<?> saveOrUpdate(@RequestBody @Valid ${entityClassName} ${entityVarName}){
        int rs = ${serviceVarName}.saveOrUpdate(${entityVarName});
        if(rs != 0){
            return XyResponseEntity.ok();
        }
        return XyResponseEntity.ok(XyRetCodeConstant.COMMON_OPERATION_FAILTURE);
    }

    @ApiOperation(value = "删除记录")
    @PostMapping("/delete")
    public ResponseEntity<?> delete(@RequestParam ${primaryKey.type} ${primaryKey.varName}){
        int rs = ${serviceVarName}.delete(${primaryKey.varName});
        if(rs != 0){
            return XyResponseEntity.ok();
        }
        return XyResponseEntity.ok(XyRetCodeConstant.COMMON_OPERATION_FAILTURE);
    }
}
